home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / pprd100 / jd.pl < prev    next >
Perl Script  |  1996-07-10  |  1KB  |  45 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # edit this to the printer hostname
  4. $them = 'printer';
  5. $port = 9100;
  6.  
  7. open(STDIN, "@ARGV[0]") if $#ARGV >= 0;
  8.  
  9. require 'sys/socket.ph';
  10.  
  11. $sockaddr = 'S n a4 x8';
  12. chop($hostname = `hostname`);
  13.  
  14. ($name, $aliases, $proto) = getprotobyname('tcp');
  15. ($name, $aliases, $port) = getservbyname($port, 'tcp')
  16.     unless $port =~ /^\d+$/;
  17. ($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname);
  18. ($name, $aliases, $type, $len, $thataddr) = gethostbyname($them);
  19.  
  20. socket(S, &PF_INET, &SOCK_STREAM, $proto) || &errexit("socket: $!\n");
  21.  
  22. $this = pack($sockaddr, &AF_INET, 0, $thisaddr);
  23. bind(S, $this) || &errexit("bind: $!\n");
  24.  
  25. $that = pack($sockaddr, &AF_INET, $port, $thataddr);
  26. connect(S, $that) || &errexit("connect: $!\n");
  27.  
  28. select(S); $| = 1; select(stdout);
  29.  
  30. while (1)
  31. {
  32.     $nread = read(STDIN, $buffer, 1024);
  33.     last if $nread == 0;
  34.     &errexit("write: $!\n") unless
  35.         defined($written = syswrite(S,$buffer,$nread));
  36. }
  37. close(S);
  38. exit 0;
  39.  
  40. sub errexit
  41. {
  42.     print STDERR @_;
  43.     exit 2;
  44. }
  45.